
function setTableCSS(tableId) {
	$("#" + tableId).addClass("ui-widget-content ui-corner-all listtable");
	$("#" + tableId +" thead tr").addClass("ui-widget-header ui-widget-content ui-corner-all");
	$("#" + tableId + " .bodytdbackground").removeClass("bodytdbackground");
	$("#" + tableId).each(function() {
		$(this).find("tbody tr:odd").addClass("bodytdbackground");
		$(this).find("tr").find("td:last").css("border-width", "0px");
	});
}

function clearInput(objId){
	$("#"+objId + " input,select").val("");
}

function clickSelect(thistr){
	var objTr = $(thistr);
	if (objTr.hasClass("ui-state-active")) {
		objTr.removeClass("ui-state-active");
	} else {
		objTr.addClass("ui-state-active");
	}
}

function selectAllForList(listId){
	//$("#"+listId + " tbody").find("input[type='checkbox']").attr("checked",$("#"+listId+" thead input:checked").size() == 1);
	var checkboxes = $("#"+listId + " tbody").find("input[type='checkbox']");
	var bool = $("#"+listId+" thead input:checked").size() == 1;
	for (var i=0; i<checkboxes.length; i++) {
		checkboxes.get(i).checked = bool;
	}
}

function removeDuplicate(removedObjId, primaryObjId) {
	var prTrObjs = $("#" + primaryObjId + " tbody tr");
	var rmTrObjs = $("#" + removedObjId + " tbody");
	for (var i = 0; i < prTrObjs.size(); i++) {
		var trObjId = prTrObjs.eq(i).attr("id");
		if (rmTrObjs.has("#" + trObjId)) {
			rmTrObjs.find("#" + trObjId).html("");
			rmTrObjs.find("#" + trObjId).remove("tr");
		}
	}
	setTableCSS(removedObjId);
} 

function moveFromObjToObj(fromObjId,toObjId) {
	var moveObjs = $("#" + fromObjId).find(".ui-state-active");
	$("#" + toObjId + " tbody").append(moveObjs);
	setTableCSS(fromObjId);
	setTableCSS(toObjId);
}

function moveFromObjToObjAll(fromObjId,toObjId) {
	//$("#" + fromObjId + " tbody tr").addClass("ui-state-active");
	//moveFromObjToObj(fromObjId,toObjId);
	$("#" + toObjId + " tbody").append($("#" + fromObjId + " tbody tr"));
}


var dialogType = {warning:"warning",error:"error",tick:"tick",info:"info"};
function showMessageDialog(title,message,okFunction,type){
	$("#warningdialog").attr("title",title);
	$("#warningdialog .dialogpng").attr("src","imgs/dialog_" + type + ".png");
	$("#warningdialog .warningdialogmessage").html(message);
	if (okFunction != null) {
		$("#warningdialog").dialog({
			width: 328,
			resizable: false,
			modal: true,
			buttons: {
				"确定": function(){okFunction.call();$(this).dialog("close");},
				"取消": function(){$(this).dialog("close");}
			}
		});
	} else {
		$("#warningdialog").dialog({
			width: 328,
			resizable: false,
			modal: true,
			buttons: {
				"确定": function() {	$(this).dialog("close");}
			}
		});		
	}
}

